package main.java.DMDE.view;

import java.awt.Container;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import main.java.DMDE.model.Modifier;
import main.java.DMDE.model.Visibility;

import com.jgoodies.forms.factories.CC;
import com.jgoodies.forms.layout.FormLayout;


public abstract class CommonEntityView {
    
    protected IOperationView operatView;
    protected JFrame frame1;
    protected JTabbedPane tabbedPane;
    protected JButton createButton;
    protected JPanel generalPanel;
    protected JLabel classNameText;
    protected JTextField className;
    protected Container frame1ContentPane;
    
    public CommonEntityView(){}
    
    protected void initComponents() {

 	frame1 = new JFrame();
 	tabbedPane = new JTabbedPane();
 	createButton = new JButton();
 	frame1ContentPane = frame1.getContentPane();

 	initGeneralPanel();

 	tabbedPane.addTab("General settings", generalPanel);

 	frame1ContentPane.add(tabbedPane, CC.xywh(5, 11, 145, 120));

 	// ---- createButton ----
 	createButton.setText("Finish");
 	frame1ContentPane.add(createButton, CC.xy(149, 147));
 	frame1.pack();
 	frame1.setLocationRelativeTo(frame1.getOwner());

     }
    
    protected abstract void initGeneralPanel();
    
   
    public void addCommonOperationView(IOperationView operatView) {
	this.operatView = operatView;
	JPanel operationPanel = this.operatView.getPanel();
	tabbedPane.addTab("Operation", operationPanel);
    }
    
    public void showView() {
	this.frame1.setVisible(true);
    }
    
    public void setModeUpdating() {
	this.frame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }

    protected void showWrongClassNameDialog() {
  	if (className.getText().equals("")) {
  	    JOptionPane.showMessageDialog(null,
  		    "A class must have a name, please complete it.",
  		    "Invalid Entity Name", JOptionPane.QUESTION_MESSAGE);
  	} else
  	    JOptionPane
  		    .showMessageDialog(
  			    null,
  			    this.className.getText()
  				    + " already exists as a class name on this project, please change it.",
  			    "Invalid Entity Name", JOptionPane.QUESTION_MESSAGE);
      }
  
    
}
